Skip to content

common: parse the raw rpc responses with python's own json, and fix the raw bindings - #154

Open
mycomputercrashsalot wants to merge 6 commits into
libmonero:mainfrom
mycomputercrashsalot:raw-rpc-responses
Open

mycomputercrashsalot wants to merge 6 commits into
libmonero:mainfrom
mycomputercrashsalot:raw-rpc-responses

Conversation

@mycomputercrashsalot

Copy link
Copy Markdown
Contributor

the raw rpc responses went thru a boost property tree, wich erases the difference between {},
[] and "" before python sees anything: every empty container came back as a string. the two
json endpoints fetch the raw body now (a one line passthrough to the invoke the connection
already had, no envelope duplicated) and parse it with python's own json. {} is {}, [] is [],
"" is "", and every integer keeps its exact value at any magnitude, wich the old parse lost
past 2^53.

two things change for a caller that relied on the old shapes: malformed json raises
json.JSONDecodeError now (a ValueError, not a RuntimeError), and json null maps to None instead
of the string "null". nothing in the repo relied on either.

the old bindings also held the gil for the whole round trip, so any in-process python http peer
deadlocked on them. the gil is released around the fetch now.

the raw requests advertised a timeout_ms the bindings rejected - type checked code passed and
runtime raised TypeError. the bindings take it now and forward it to monero-cpp. one caveat the
stubs say out loud: the timeout is per request, the initial connection to a fresh host can
still take as long as the os lets it, and timeout_ms=0 means indefinite.

import_multisig_hex dropped refresh_after_import for python subclasses (the direct binding had
it, the trampoline didnt). re-assigning the same query to itself wiped the back reference wich
the guard in set_query already had. verify_message caught every exception, so an outage read as
"signature not good" - it catches the address errors now and lets the rest raise.

  • common: parse the integers of the raw rpc responses with their full 64 bit range
  • common: forward the timeout of the raw rpc requests
  • wallet: forward the refresh after import of the multisig hex
  • wallet: keep the back reference of a query reassigned to itself
  • wallet: only catch the address errors of the message verification
  • common: parse the raw rpc responses with python's own json
  • common: document the timeout caveats of the raw requests and the connection check
  • wallet: test the trampoline forwarding of the multisig hex import

the suite: 70 passed, 2 xfailed, 1 environmental (a loopback response_time that reads 0ms - it
fails the same way on the tree before these changes).

@codacy-production

codacy-production Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 high

Alerts:
⚠ 1 issue (≤ 0 issues of at least minor severity)

Results:
1 new issue

Category Results
ErrorProne 1 high

View in Codacy

🟢 Metrics 10 complexity · 3 duplication

Metric Results
Complexity 10
Duplication 3

View in Codacy

🟢 Coverage 98.65% diff coverage · +0.03% coverage variation

Metric Results
Coverage variation ✅ +0.03% coverage variation (-1.00%)
Diff coverage ✅ 98.65% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (f5f6bc4) 18075 16813 93.02%
Head commit (e4ff1e8) 18182 (+107) 16918 (+105) 93.05% (+0.03%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#154) 148 146 98.65%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@everoddandeven

Copy link
Copy Markdown
Member

Thanks, there are some good fixes here, but I think this should be split up:

These can go in now as a separate PR:

  • forward timeout_ms in the raw request bindings
  • forward refresh_after_import in the import_multisig_hex trampoline
  • keep the back reference when a query is reassigned to itself

The import_key_images offset fix is already on main, so that commit can be dropped on rebase

Raw responses: agreed the property tree loses information, but I'd rather not subclass monero_rpc_connection just to reach the protected invoke_post. The bindings cast connections that were never constructed as PyMoneroRpcConnection (anything from MoneroRpcConnection(uri) or from C++). I think we should just make invoke_post public in monero-cpp. The bindings can then serialize the request with the GIL held, call invoke_post without it, and json.loads the body. No subclass, and the http client, auth, timeouts and http errors stay in one place. The jsonrpc error check would still be duplicated here, unless monero-cpp also exposes raise_rpc_error, which could be worth doing at the same time. Malformed json should also raise MoneroError rather than JSONDecodeError

verify_message: agree it shouldn't swallow everything, but matching on monero-cpp's error strings will break as soon as they change. I think wallet full and wallet keys should return a bad result for an invalid address themselves in monero-cpp, then the binding doesn't need to inspect messages. This change is also what breaks the unit tests on linux and mac: test_interface.py::test_verify_message now gets "verify_message() not supported" from the base wallet

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants